package com.caregiver.watch.business.user.model.vo;

import com.caregiver.watch.business.user.model.bo.UnreadMessageCountBo;
import com.caregiver.watch.business.user.model.po.UserChatMessage;
import com.caregiver.watch.business.user.model.po.UserChatWindowInfo;
import com.caregiver.watch.common.constant.NumberConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Optional;

/**
 * @Description: 聊天窗口
 * @Author 疆戟
 * @Date 2025/8/30 15:42
 * @Version 1.0
 */
@Data
@Schema(description = "聊天窗口")
public class ChatWindowVo {

    @Schema(description = "聊天窗口ID")
    private Long chatWindowId;

    @Schema(description = "用户ID")
    private Long userId;

    @Schema(description = "被照护人ID")
    private Long recipientId;

    @Schema(description = "未读消息数")
    private Integer unreadMessageCount;

    @Schema(description = "最后消息")
    private ChatMessageVo lastMessage;


    public static ChatWindowVo build(UserChatWindowInfo userChatWindowInfo, UnreadMessageCountBo countBo, UserChatMessage lastMessage) {
        ChatWindowVo vo = new ChatWindowVo();
        vo.chatWindowId = userChatWindowInfo.getChatWindowId();
        vo.userId = userChatWindowInfo.getUserId();
        vo.recipientId = userChatWindowInfo.getRecipientId();
        vo.unreadMessageCount = Optional.ofNullable(countBo).map(UnreadMessageCountBo::getUnreadCount).orElse(NumberConstants.ZERO);
        vo.lastMessage = ChatMessageVo.build(lastMessage);
        return vo;
    }
}
